<template>
  <div class="found">
    <!-- 轮播图 -->
    <Carousel :list="carouselList" />

    <!-- 推荐歌单 -->
    <div class="musiclist">
      <h4 class="title">推荐歌单</h4>
      <PlayListCard
        v-for="item in playList"
        :key="item.id"
        :id="item.id"
        :img="item.picUrl"
        :name="item.name"
        :desc="item.copywriter"
        @handelMusicItem="handelMusicItem"
      />
    </div>

    <!-- 最新音乐 -->
    <div class="news">
      <h3 class="title">最新音乐</h3>
      <div class="items">
        <div
          class="item"
          v-for="(item, index) in newSongsList"
          :key="index"
          @click="playMusic(item)"
        >
          <div class="img-wrap">
            <img v-lazy="item.picUrl+'?param=130y130'" alt />
            <span class="iconfont icon-play"></span>
          </div>
          <div class="song-wrap">
            <div class="song-name">{{ item.name }}</div>
            <div class="singer">{{ item.song.artists[0].name }}</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 最新mv -->
    <div class="mvs">
      <h3 class="title">推荐MV</h3>
      <div class="mv">
        <MvCard
          v-for="item in mvs"
          :key="item.id"
          :author="item.artistName"
          :id="item.id"
          :img="item.picUrl"
          :name="item.name"
          :playCount="item.playCount"
        />
      </div>
    </div>
  </div>
</template>

<script>
import Carousel from '@/components/Carousel/Carousel'
import PlayListCard from '../../components/playlist/playlist'
import MvCard from '../../components/mvcard/mvcard'
import { reqBanner, reqPersonalizedPlaylist, reqPersonalizedNewsong, reqPersonalizedMv } from '../../requset/api'
export default {
  name: '',
  data () {
    return {
      carouselList: [],
      playList: [],
      newSongsList: [],
      mvs: []
    };
  },
  methods: {
    // 轮播图
    async getBanner () {
      const result = await reqBanner({ clientType: 'pc' })
      this.carouselList = result.banners
    },
    // 获取推荐歌单
    async getPlayList () {
      const { result: playList } = await reqPersonalizedPlaylist({ limit: '10' })
      this.playList = playList
    },

    // 最新歌曲
    async getNewSong () {
      const res = await reqPersonalizedNewsong({ type: 'recommend' })
      this.newSongsList = res.result
    },

    // 最新mv
    async getMvs () {
      const res = await reqPersonalizedMv()
      this.mvs = res.result
    },


    handelMusicItem (id) {
      this.$router.push(`/playlist/${id}`)
    },

    // 最新音乐
    playMusic (item) {
      console.log(item)
    }
  },
  created () {
    this.getBanner()
    this.getPlayList()
    this.getNewSong()
    this.getMvs()
  },
  components: {
    Carousel,
    PlayListCard,
    MvCard
  }
}

</script>
<style lang='less' scoped>
.found {
  width: 100%;
  height: 100%;
  .musiclist {
    width: 100%;
    .title {
      padding: 10px 2px;
    }
  }
  .news {
    margin-bottom: 40px;
    .items {
      height: 500px;
      display: flex;
      flex-direction: column;
      flex-wrap: wrap;
      .item {
        cursor: pointer;
        height: 100px;
        width: 50%;
        display: flex;
        align-items: center;
        &:hover {
          background-color: rgba(0, 0, 0, 0.1);
        }
        .index {
          margin-right: 15px;
          font-size: 15px;
        }

        .img-wrap {
          position: relative;
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;

          img {
            width: 80px;
            height: 80px;
          }
          .iconfont {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 30px;
            height: 30px;
            color: #dd6d60;
            text-align: center;
            line-height: 30px;
            border-radius: 50%;
            font-size: 14px;
            background: rgba(255, 255, 255, 0.8);
            opacity: 0;

            &::before {
              transform: translateX(3px);
            }
          }

          &:hover .iconfont {
            opacity: 1;
          }
        }

        .song-wrap {
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          height: 100%;
          padding: 10px;
          font-size: 16px;
          .singer {
            font-size: 14px;
            color: gray;
          }
        }
      }
    }
  }

  .mv {
    display: flex;
    justify-content: space-around;
  }
}
</style>
